package com.haiyou.common.util;

import tk.mybatis.mapper.entity.Example;

/**
 * @author chenzeke
 * @date 2019/10/17 22:20
 */
public class SortUtil {

    public static void sort(Example example, String orderType, String orderKey) {
        if ("asc".equals(orderType)) {
            example.orderBy(orderKey).asc();
        } else {
            example.orderBy(orderKey).desc();
        }
    }
    public static void andGreaterOrLessOrBetween(Example.Criteria criteria, String key, Object count1, Object count2) {
        if (count1 != null && count2 != null) {
            criteria.andBetween(key, count1, count2);
        } else {
            if (count1 != null) {
                criteria.andGreaterThanOrEqualTo(key, count1);
            }
            if (count2 != null) {
                criteria.andLessThanOrEqualTo(key, count2);
            }
        }
    }
}
